<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">消耗记录</ui:define>
    <ui:define name="content">


        <h:form id="incomeForm">
            <p:dialog header="操作执行中,请稍候" widgetVar="doing" modal="true" closable="false" resizable="false"
                      draggable="false"/>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix" style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>
                        <p:columnToggler datasource="statisticRecordDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton value="新增" actionListener="#{settlementIncomeListBean.onAdd(null)}"
                                         oncomplete="PF('adding').show();" process="@this" update="@form"
                                         icon="fa fa-plus">
                        </p:commandButton>
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         onstart="PF('doing').show()"
                                         update="@form"/>
                        <p:commandButton value="重置" actionListener="#{settlementIncomeListBean.onReset()}"
                                         icon="fa fa-refresh"
                                         process="@this" update="@form"/>
                        <p:commandButton value="开票" actionListener="#{settlementIncomeListBean.onBill()}"
                                         icon="fa fa-refresh"
                                         process="@this statisticRecordDataTable"/>
                        <p:commandButton value="导出" icon="fa fa-download"
                                         ajax="false">
                            <p:dataExporter type="xls" target="statisticRecordDataTable" fileName="消耗记录"/>
                        </p:commandButton>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-g ui-fluid" style="padding-top: 30px;">
                <div class="ui-g-12">
                    <div class="ui-g-12 card">
                        <h1>查询条件</h1>
                        <div class="ui-g-1">
                            <p:outputLabel value="产品名称"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu id="productId" value="#{settlementIncomeListBean.$.productId}"
                                             filter="true" updateLabel="true"
                                             filterMatchMode="contains">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems value="#{settlementIncomeListBean.productList}"
                                               var="dic"
                                               itemLabel="#{dic.productName}" itemValue="#{dic.id}"/>
                            </p:selectOneMenu>
                        </div>
                        <div class="ui-g-1">
                            <p:outputLabel value="主体名称"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu id="companyId" value="#{settlementIncomeListBean.$.companyId}"
                                             filter="true" updateLabel="true"
                                             filterMatchMode="contains">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems value="#{settlementIncomeListBean.companyList}"
                                               var="dic"
                                               itemLabel="#{dic.companyName}" itemValue="#{dic.id}"/>
                            </p:selectOneMenu>
                        </div>
                        <div class="ui-g-1">
                            <p:outputLabel value="合作模式"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu id="copMode" value="#{settlementIncomeListBean.$.copMode}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{settlementIncomeListBean.dictionaries[DictionaryCode.COOPERATION_MODE]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>
                        <div class="ui-g-1">
                            <p:outputLabel value="推广方式"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu id="spreadMode" value="#{settlementIncomeListBean.$.spreadMode}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{settlementIncomeListBean.dictionaries[DictionaryCode.SETTLEMENT_SPREAD_MODE]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>
                        <div class="ui-g-1">
                            <p:outputLabel value="推广渠道"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu id="spreadChannel" value="#{settlementIncomeListBean.$.spreadChannel}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{settlementIncomeListBean.dictionaries[DictionaryCode.SETTLEMENT_SPREAD_CHANNEL]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>
                        <div class="ui-g-1">
                            <p:outputLabel value="结算模式"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu id="settlementMode" value="#{settlementIncomeListBean.$.settlementMode}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{settlementIncomeListBean.dictionaries[DictionaryCode.SETTLEMENT_CYCLE]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>
                        <div class="ui-g-1">
                            <p:outputLabel value="开票状态"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu id="billStatus" value="#{settlementIncomeListBean.$.billStatus}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{settlementIncomeListBean.dictionaries[DictionaryCode.SETTLEMENT_BILL_STATUS]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="结算时间"/>
                        </div>
                        <div class="ui-g-3">
                            <p:calendar
                                    id="startTime" styleClass="autoWidthCalendar"
                                    value="#{settlementIncomeListBean.$.startTime}"
                                    locale="#{constants:get('LOCALE')}"
                                    timeZone="#{constants:get('TIME_ZONE')}"
                                    pattern="#{constants:get('DATE_FORMAT')}"/>
                            <span>—</span>
                            <p:calendar
                                    id="endTime" styleClass="autoWidthCalendar"
                                    value="#{settlementIncomeListBean.$.endTime}"
                                    locale="#{constants:get('LOCALE')}"
                                    timeZone="#{constants:get('TIME_ZONE')}"
                                    pattern="#{constants:get('DATE_FORMAT')}"/>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="收入类型"/>
                        </div>
                        <div class="ui-g-3">
                            <p:selectOneMenu value="#{settlementIncomeListBean.$.incomeType}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems
                                        value="#{settlementIncomeListBean.dictionaries[DictionaryCode.SETTLEMENT_INCOME_TYPE]}"
                                        var="dic"
                                        itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>

                        <div class="ui-g-1">
                            <p:outputLabel value="创建人"/>
                        </div>
                        <div class="ui-g-3">
                            <p:inputText id="creator" value="#{settlementIncomeListBean.$.creator}"/>
                        </div>



                    </div>

                    <div class="ui-g-12 card">
                        <p:dataTable id="statisticRecordDataTable"
                                     style="width: 100%;text-align:center"
                                     var="record"
                                     value="#{settlementIncomeListBean.lazyDataModel}"
                                     rows="#{constants:get('ROWS')}"
                                     lazy="true"
                                     paginator="true"
                                     paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                     rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                     emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                     scrollable="true"
                                     scrollWidth="98%"
                                     reflow="true"
                                     selection="#{settlementIncomeListBean.selectIncomeList}" rowKey="#{record.id}"
                                     resizableColumns="true">
                            <p:column selectionMode="multiple" style="width:16px;text-align:center" exportable="false"/>

                            <p:column headerText="操作" exportable="false">
                                <p:splitButton icon="fa fa-eye"
                                               process="@this"
                                               actionListener="#{settlementIncomeListBean.onSee(record.id)}"
                                               oncomplete="PF('adding').show();" update="@form">
                                    <f:setPropertyActionListener
                                            value="/views/settlementsystem/income-list.xhtml"
                                            target="#{currentUserBean.back}"/>
                                </p:splitButton>
                            </p:column>
                            <p:column headerText="主体流水号">
                                <h:outputText value="#{record.companyId}"/>
                            </p:column>
                            <p:column headerText="产品流水号">
                                <h:outputText value="#{record.productId}"/>
                            </p:column>
                            <p:column headerText="开始时间" style="text-align:center;width: 70px">
                                <h:outputText value="#{record.startTime}">
                                    <f:convertDateTime pattern="#{constants:get('DATE_FORMAT')}"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="结束时间" style="text-align:center;width: 70px">
                                <h:outputText value="#{record.endTime}">
                                    <f:convertDateTime pattern="#{constants:get('DATE_FORMAT')}"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="产品名称">
                                <h:outputText value="#{record.productName}"/>
                            </p:column>
                            <p:column headerText="所属主体">
                                <h:outputText value="#{record.companyName}"/>
                            </p:column>
                            <p:column headerText="收入类型" style="text-align:center;">
                                <h:outputText
                                        value="#{settlementIncomeListBean.translate(DictionaryCode.SETTLEMENT_INCOME_TYPE,record.incomeType)}"/>
                            </p:column>
                            <p:column headerText="推广方式" style="text-align:center;">
                                <h:outputText
                                        value="#{settlementIncomeListBean.translate(DictionaryCode.SETTLEMENT_SPREAD_MODE,record.spreadMode)}"/>
                            </p:column>
                            <p:column headerText="推广渠道" style="text-align:center;">
                                <h:outputText
                                        value="#{settlementIncomeListBean.translate(DictionaryCode.SETTLEMENT_SPREAD_CHANNEL,record.spreadChannel)}"/>
                            </p:column>
                            <p:column headerText="合作模式" style="text-align:center;">
                                <h:outputText
                                        value="#{settlementIncomeListBean.translate(DictionaryCode.COOPERATION_MODE,record.copMode)}"/>
                            </p:column>
                            <p:column headerText="结算方式" style="text-align:center;">
                                <h:outputText
                                        value="#{settlementIncomeListBean.translate(DictionaryCode.SETTLEMENT_CYCLE,record.settlementMode)}"/>
                            </p:column>

                            <p:column headerText="结算单价(元)" style="text-align:center;">
                                <h:outputText value="#{record.priceCpa == null ?'-':record.priceCpa}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="结算单价(%)" style="text-align:center;">
                                <h:outputText value="#{record.priceCps == null?'-':record.priceCps}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="注册数" style="text-align:center;">
                                <h:outputText value="#{record.registerCount == null ?'-': record.registerCount}"/>
                            </p:column>
                            <p:column headerText="放款金额" style="text-align:center;">
                                <h:outputText value="#{record.lendAmount == null ?'-': record.lendAmount}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="点击数" style="text-align:center;">
                                <h:outputText value="#{record.clickCount == null ?'-': record.clickCount}"/>
                            </p:column>
                            <p:column headerText="结算金额" style="text-align:center;">
                                <h:outputText value="#{record.incomeAmount}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="参与UV" style="text-align:center;">
                                <h:outputText value="#{record.participateUv}"/>
                            </p:column>
                            <p:column headerText="UV价值" style="text-align:center;">
                                <h:outputText value="#{record.uvValue}">
                                    <f:convertNumber pattern="#,##0.00"/>
                                </h:outputText>
                            </p:column>
                            <p:column headerText="开票状态" style="text-align:center;">
                                <h:outputText
                                        value="#{settlementIncomeListBean.translate(DictionaryCode.SETTLEMENT_BILL_STATUS,record.billStatus)}"/>
                            </p:column>
                            <p:column headerText="创建人" style="text-align:center;">
                                <h:outputText value="#{record.creator}"/>
                            </p:column>
                            <p:column headerText="创建时间" style="text-align:center;width: 100px">
                                <h:outputText value="#{record.createTime}">
                                    <f:convertDateTime pattern="#{constants:get('DATETIME_FORMAT')}"/>
                                </h:outputText>
                            </p:column>
                        </p:dataTable>
                    </div>
                </div>
            </div>

            <ui:include src="income-info-dialog.xhtml"/>
            <ui:include src="income-bill-dialog.xhtml"/>
            <ui:include src="income-bill-annex-upload-dialog.xhtml"/>
        </h:form>
    </ui:define>
</ui:composition>